
package com.ctyun.xstore.s3.api.bucket;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.*;
import com.ctyun.xstore.s3.client.AmazonS3ClientBuilder;


public class SetBucketAcl {
    public static void setBucketAcl(String bucketName) {
        AmazonS3 s3 = AmazonS3ClientBuilder.buildAmazonS3Client();
        try {
            // get the current ACL
            AccessControlList acl = s3.getBucketAcl(bucketName);
            // Retrieve the bucket's ACL, add another grant, and then save the new ACL.
            // 给所有用户授予读取权限
            Grant grant = new Grant(GroupGrantee.AllUsers, Permission.Read);
            acl.grantAllPermissions(grant);
            s3.setBucketAcl(bucketName, acl);
        } catch (AmazonServiceException e) {
            System.err.println(e.getErrorMessage());
        }
        System.out.println("Done!");
    }

}
